package com.example.meijun.pantest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;

import java.io.File;
import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.example.meijun.pantest.Test.baseUrl;
import static com.example.meijun.pantest.Test.downurl;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    @Bind(R.id.progressBar1)
    ProgressBar progressBar1;
    @Bind(R.id.button1)
    Button button1;
    @Bind(R.id.progressBar2)
    ProgressBar progressBar2;
    @Bind(R.id.button2)
    Button button2;
    @Bind(R.id.progressBar3)
    ProgressBar progressBar3;
    @Bind(R.id.button3)
    Button button3;
    @Bind(R.id.progressBar4)
    ProgressBar progressBar4;
    @Bind(R.id.button4)
    Button button4;
    @Bind(R.id.progressBar5)
    ProgressBar progressBar5;
    @Bind(R.id.button5)
    Button button5;
    private ProgressDownloader progressDownloader;
    private long havewrite = 0;
    private String url;
    private Thread thread;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        String format = String.format(downurl, "1f1fedc2-de99-47f3-967b-4944b38af14c");
        url = baseUrl + format;



    }

    @OnClick({R.id.button1, R.id.button2, R.id.button3, R.id.button4, R.id.button5})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.button1:


                HashMap<String, String> params = new HashMap<>();
                params.put("fildid","1f1fedc2-de99-47f3-967b-4944b38af14c");
                DownLoadManager.getInstance().addTask(new DownloadItem(url, new File("/sdcard/abcc1.tar"), params, new ProgressResponseBody.ProgressListener() {
                    @Override
                    public void onPreExecute(long contentLength) {
                        Log.e(TAG, "onPreExecute: " + contentLength);
                        progressBar1.setMax((int) contentLength);
                    }

                    @Override
                    public void update(long totalBytes, boolean done) {
                        Log.e(TAG, "update: +total" + totalBytes + done);
                        progressBar1.setProgress((int) totalBytes);
                    }

                    @Override
                    public void cancle() {

                    }
                }));


                break;
        }
    }
}
